const dynamicModel = require('@/models/dynamic.model')
const Service = require('./index')

class DynamicService extends Service {
  /**
   * 动态分页查询
   * @param {*} pageNo
   * @param {*} pageSize
   * @param {*} nickname
   */
  async findPage (pageNo = 1, pageSize = 20, searchKeywords, type) {
    try {
      const { list, total } = await dynamicModel.findPage({
        pageNo,
        pageSize,
        conditions: {
          like: {
            'user.nickname': searchKeywords
          },
          equal: {
            'dynamics.type': type
          }
        }
      })
      return this.skipPage(list, total, pageNo, pageSize)
    } catch (error) {
      throw new Error(error)
    }
  }

  async batchDelete (ids) {
    if (!ids?.length) {
      return {
        errorMessage: 'ids 不能为空'
      }
    }
    try {
      await dynamicModel.delete(ids)
    } catch (error) {
      throw new Error(error)
    }
  }
}

module.exports = new DynamicService()
